<?
include('../controller/handler.php');

include('../module/var.inc.php');

session_start();

$hd = new Handler();
$base_url = $hd->getBaseURL();

if($_POST!=NULL && $hd->getPassword()==sha1($_SESSION['password'])) {
	if($_POST['new_pwd']==$_POST['conf_pwd'] && $_POST['new_pwd']!="" && sha1($_POST['old_pwd'])==$hd->getPassword()) {
		$hd->changePassword(sha1($_POST['new_pwd']));
		$hd->writeLog("[PASSWORD] ".strftime("%c")." password changed by ".$hd->getUsername().
			" ID=".$_SERVER['REMOTE_ADDR']);
		$feedback = "Cambio password effettuato con successo.";
	} else {
		$feedback = "Impossibile cambiare la password, verificare i dati inseriti.";
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head>
	<? include('../module/head.inc.php'); ?>
	<meta name="robots" content="noindex, nofollow"/>
</head>

<body>
<div id="content">
<?include('../module/header.inc.php');?>

<?if($hd->getPassword()==sha1($_SESSION['password'])) {?>

<div class="form">
	<div class="upper_bar_main"><div class="upper_bar_round"></div></div>
	<div class="body_main_left">
	<div class="body_main_right">
	<div class="body_main">
	<form action="password" method="post" accept-charset="utf-8" onsubmit="return confirmChangePwd(this);;">
		<h2>Cambia Password</h2>
		<input type="password" class="text" name="old_pwd" value="" /> Vecchia password<br />
		<input type="password" class="text" name="new_pwd" value="" /> Nuova password<br />
		<input type="password" class="text" name="conf_pwd" value="" /> Conferma nuova password

		<p><input type="submit" value="Conferma &rarr;"></p>
	</form>
	<?if($feedback) {?><p id="feedback" class="highline"><?echo $feedback;?></p> <?}?>
	<p class="small admin_action">
		<a href="<?echo $base_url;?>panel">&larr; Pannello di amministrazione</a> |
		<a href="<?echo $base_url;?>panel/preferences">Modifica preferenze</a>
	</p>
	</div></div></div>
	<div class="lower_bar_main"><div class="lower_bar_round"></div></div>
</div>

<?}?>

<? include('../module/footer.inc.php'); ?>
</div>
</body>
</html>
